<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,user-scalable=no, initial-scale=1">
		<title>添加拜访记录</title>			
		<link rel="stylesheet" type="text/css" href="/azxcrm/css/wap/mui.min.css" th:href="@{/azxcrm/css/wap/mui.min.css}"/>
		<link rel="stylesheet" type="text/css" href="/azxcrm/css/wap/mui.picker.min.css" th:href="@{/azxcrm/css/wap/mui.picker.min.css}"/>
		<link rel="stylesheet" type="text/css" href="/azxcrm/css/wap/aui.css" th:href="@{/azxcrm/css/wap/aui.css}"/>
		<link rel="stylesheet" type="text/css" href="/azxcrm/css/wap/add_record.css" th:href="@{/azxcrm/css/wap/add_record.css}"/>
		<link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_835360_5n3z54a5m1.css"/>
		<script src="/azxcrm/js/wap/mui.min.js" th:src="@{/azxcrm/js/wap/mui.min.js}" type="text/javascript" charset="utf-8"></script>
		<script src="/azxcrm/js/wap/mui.picker.min.js" th:src="@{/azxcrm/js/wap/mui.picker.min.js}" type="text/javascript" charset="utf-8"></script>
		<script src="/azxcrm/js/wap/city.data-3.js" th:src="@{/azxcrm/js/wap/city.data-3.js}" type="text/javascript" charset="utf-8"></script>
		<script src="../static/js/jquery.min.js" th:src="@{/js/jquery.min.js}"></script>
		<script th:inline="javascript"> var ctx = [[@{/}]]; </script>
	</head>
	<body>
		<header class="aui-bar aui-bar-nav">
			 <a href="javascript:history.back(-1)" class="aui-pull-left aui-btn">
	       		 <span class="iconfont icon-fanhui1">返回</span>
	    	</a>
		    <div class="aui-title">添加拜访记录</div>
		</header>
		<form id="add_Record">
		<section class="aui-grid aui-margin-b-15">
			<div class="aui-content aui-margin-b-15">
			    <ul class="aui-list aui-list-in">		       
			        <li class="aui-list-item">
			            <div class="aui-list-item-inner aui-list-item-arrow" id="phone">
			            	<div class="clearfix">
			            		<div class="aui-list-item-title">拜访类型：</div>	
			                	<div class="aui-text" >选择拜访类型</div>
			                	<input type="hidden" id="visitId" name="visitId">
			                	<input type="hidden" id="visitType" name="visitType">
			            	</div>			                
			            </div>
			        </li>		
			    </ul>
			</div>
			
			<div class="aui-content aui-margin-b-15 g-order2">
				<ul class="aui-list aui-form-list">
			        <li class="aui-list-header">
						<div class="s-order">
							<div>沟通记录</div>
						</div>
			        </li>
					<li class="aui-list-item">
			            <div class="aui-list-item-inner">
			                <div class="aui-list-item-input">
			                    <textarea placeholder="请填写拜访记录" id="visitRecord" name="visitRecord"></textarea>
			                </div>
			            </div>
			        </li>
			        <li class="aui-list-header">
						<div class="s-order">
							<div>备注</div>
						</div>
			        </li>
					<li class="aui-list-item">
			            <div class="aui-list-item-inner">
			                <div class="aui-list-item-input">
			                    <textarea class="g-remark" placeholder="请填写备注" id="visitRemark" name="visitRemark"></textarea>
			                </div>
			            </div>
			       </li>
			   </ul>
		   </div>
		   <div class="aui-content aui-margin-b-15">
			    <ul class="aui-list aui-list-in g-ul">		       
			        <li class="aui-list-item g-appoint">
			            <div class="aui-list-item-inner aui-list-item-arrow">
				            <div class="aui-list-item-label">拜访时间：</div>
			                <div class="aui-list-item-input">
			                    <input type="text" id="date" name="visitTime" placeholder="请选择日期">
			                </div>		                
				        </div>	
			        </li>	
			        <li class="aui-list-item g-appoint">
			            <div class="aui-list-item-inner aui-list-item-arrow">
			            <div class="aui-list-item-label">下次约定：</div>
			                <div class="aui-list-item-input">
			                    <input type="text" id="date2" name="nextVisitTime" placeholder="请选择日期">
			                </div>		                
			            </div>
			        </li>
			    </ul>
		   </div>
			<footer class="aui-bar aui-bar-tab" id="footer">
			 		<input type="hidden" id="clueId" name="clueId" th:value="${clueId}">
			 		<input type="hidden" id="status" name="status" th:value="${status}">
			        <button type="button" class="aui-bar aui-bar-tab" id="toastBtn" onclick="return check(this.form)">确认添加 </button>           
		   </footer>
		</section>
		</form>
	</body>
</html>
<script>
var arr = [];
var data = document.getElementById("date"); 
var data2=document.getElementById("date2")
var phone=document.getElementById("phone");
var clueId=document.getElementById("clueId").value;
var status=document.getElementById("status").value;
$.ajax({
		cache : true,
		type : "get",
		url : ctx + "/wap/customer/getVisit",
		data :'',
		async : false,
		error : function(res) {
			mui.toast("系统错误");
		},
		success : function(data) {				
			for(var i=0;i<data.length;i++){
				arr.push({
					value:data[i].dictCode,
					text:data[i].dictLabel
				})
			
			}	
			Init(arr);
		}
		});
	
			
		
	function Init(arr){
		var phone_data= new mui.PopPicker();
		phone_data.setData(arr)
		phone.addEventListener('tap', function() {
			phone_data.show(function(items) {
				document.getElementsByClassName('aui-text')[0].innerText = items[0].text;
				document.getElementById('visitId').value = items[0].value;
				document.getElementById('visitType').value = items[0].text;
				
				//返回 false 可以阻止选择框的关闭
				//return false;
			});
		}, false);
			data.addEventListener('tap', function() {
			var picker = new mui.DtPicker({type:'date'});
		      picker.show(function(rs) {
		        data.value = rs.text;
		        picker.dispose();
		      });
		})	
			data2.addEventListener('tap', function() {
			var picker = new mui.DtPicker({type:'date'});
		      picker.show(function(rs) {
		        data2.value = rs.text;
		        picker.dispose();
		      });
		})	
	
			}	
	
	function check(form) {
       	   if(form.visitType.value==''){
               mui.toast('拜访类型必选');
                 return false;
              }else if(form.visitRecord.value=='') {                
                mui.toast('沟通记录必填');
                  form.customerCellphone.focus();
                  return false;
             }else if(form.visitTime.value=='') {                
                 mui.toast('拜访时间必选');
                 form.visitTime.focus();
                 return false;
             }else{
            	$.ajax({
         		cache : true,
         		type : "POST",
         		url : ctx + "/wap/customer/saveRecord",
         		data : $("#add_Record").serialize(),
         		async : false,
         		error : function(request) {
         			mui.toast("系统错误");
         		},
         		success : function(data) {
         			if (data.code == 0) {
         				mui.toast("添加成功"); 
         				$("#toastBtn").removeAttr("onclick");
         				setTimeout(function(){
       		    	    	window.location.href= ctx + "wap/customer/customerInfo?clueId=" + clueId+"&status=" + status
        		    	    },2200)
         			} else {
         				mui.toast("添加失败");
         			}
         		}
         		});
             }     
       }
</script>
